<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        html {
            height: 100%;
        }
        
        body {
            height: 100%;
            display: flex;
            justify-content: center;
            align-items: center;
        }
        
        div.gra {
            position: relative;
        }
        
        div.father {
            position: relative;
            width: 300px;
            height: 300px;
            background-color: pink;
            padding: 10px;
            margin: 10px;
            border: 10px solid palegreen;
        }
        
        div.son {
            width: 100px;
            height: 100px;
            background-color: rosybrown;
            border: 20px solid royalblue;
            padding: 10px;
            margin: 10px;
        }
    </style>
    <script>
        window.addEventListener('load', function() {
            var div = document.querySelector('.son');
            // border + padding + content
            console.log(div.offsetWidth, div.offsetHeight);
            // padding + content
            console.log(div.clientWidth, div.clientHeight);
            // padding + content
            console.log(div.scrollWidth, div.scrollHeight);
            // 距离上层有定位的父级的距离
            console.log(div.offsetTop); // 10
            // border
            console.log(div.clientTop); // 20
            console.log(div.scrollTop); // 0
            console.log('--------------------------------------------');
            console.log(div.offsetParent);
        })
    </script>
</head>

<body>
    <div class="gra">
        <div class="father">
            <div class="son">123</div>
        </div>
    </div>
</body>

</html>